new Vue({
  el: '#app',
  data() {
    return {
      form: {
        // Article_Name: "",
        Type: "1",
        Group_Seek_Purchase_SerialNumber: '',
        token: $.cookie("token"),
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      total: 0,
      flag: true,
      category: [],
      Enterprise: [],
      tableData: [],
      group_seek_transaction_logistics: {
        Group_Seek_Logistics_SerialNumber: '',  //主键
        Group_Seek_Transaction_SerialNumber: '',  //交易流水号
        Transport_Type: '',   //运输方式
        Transport_Explain: ''  //说明
      },
      OddNumbers: false,
      loading: false,
      // Enterprise_Info_SerialNumber: $.cookie("enterprise")
    }
  },
  mounted() {
    //默认查询第一组数据
    this.getList(this.form)
    //查询所有类别
    // this.getCategoryData()
    //查询所有发布过采购的公司
    // this.getEnterpriseData()
  },
  methods: {
    //通过关键字查询数据
    onSerach() {
      this.getList(this.form)
    },
    //号码按键查询
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    //号码按键查询
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    //分页查询数据
    getList(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getGroupSeekTransactionAllAction',
        success: function (Result) {
          _this.tableData = Result.tableData;
          console.log(Result)
          _this.total = parseInt(Result.limit)
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    c(row) {
      console.log(row)
    },
    // 检验库存
    Inventory(row) {
      let _this = this
      if (this.flag) {
        _this.flag = false
        $.ajax({
          url: DomainName + '/GroupSeekCheckStockAction',
          type: 'POST',
          data: {
            Group_Seek_Purchase_SerialNumber: row.Group_Seek_Purchase_SerialNumber,
            Quantity: row.Quantity,
            token: $.cookie("token")
          },
          success: function (res) {
            console.log(res)
            if (res.Status == 'success') {
              _this.AgreePurchase(row)
              // _this.$notify({
              //   title: '成功',
              //   message: '企业审核中,请等待',
              //   type: 'success'
              // });
            } else {
              _this.$notify.error({
                title: '错误',
                message: '库存不足'
              });
            }
          },
          complete: function (XMLHttpRequest) {
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
        })
      }
    },
    ConfirmReceipt(row) {
      console.log(row)
      let _this = this;
      _this.loading = true
      row.Row_Status = '6'
      $.ajax({
        type: 'POST',
        data: {
          Group_Seek_Transaction_SerialNumber: row.Group_Seek_Transaction_SerialNumber,
          token: $.cookie("token")
        },
        url: DomainName + '/GroupSeekTransactionStateAction',
        success: function (Result) {
          console.log(Result)
          _this.getList(_this.form)
          _this.$message.success("收货成功");
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })

    },
    // 通过求购
    AgreePurchase(row) {
      let _this = this
      _this.flag = false
      $.ajax({
        type: 'POST',
        url: DomainName + '/GroupSeekTransactionExamineAction',
        data: {
          Group_Seek_Transaction_SerialNumber: row.Group_Seek_Transaction_SerialNumber,
          Audit_Status: '1',
          Cause: '',
          token: $.cookie("token")
        },
        success: function (data) {
          console.log(data)
          if (data.Status == "success") {
            _this.$message({
              type: 'success',
              message: '已通过！'
            });
            _this.getList(_this.form)
          }
        },
        complete: function (XMLHttpRequest) {
          _this.flag = true
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    // 拒绝求购
    RefuseProcurement(row) {
      let _this = this
      // console.log(row)
      this.$prompt('请输入拒绝原因，如线下沟通则说明', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^(?!\s*$).+/,
        inputErrorMessage: '原因不能由零个或多个空格组成',
        type: 'warning',
      }).then(({ value }) => {
        $.ajax({
          type: 'POST',
          url: DomainName + '/GroupSeekTransactionExamineAction',
          data: {
            Group_Seek_Transaction_SerialNumber: row.Group_Seek_Transaction_SerialNumber,
            Audit_Status: '2',
            Cause: value,
            token: $.cookie("token")
          },
          success: function (res) {
            console.log(res)
            if (res.Status == "success") {
              _this.$message({
                type: 'info',
                message: '已拒绝申请！'
              });
              _this.getList(_this.form)
            }
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        });
      });
    },
    // 跳转详情
    goDetail(row) {
      console.log(row)
      sessionStorage.setItem("Group_Seek_Purchase_SerialNumber", row.Group_Seek_Purchase_SerialNumber)
      sessionStorage.setItem("Group_Seek_Transaction_SerialNumber", row.Group_Seek_Transaction_SerialNumber)
      window.location.href = './Detail.html'
    },
    // 确认合同
    ConfirmContract(row) {
      sessionStorage.setItem("Group_Seek_Purchase_SerialNumber", row.Group_Seek_Purchase_SerialNumber)
      sessionStorage.setItem("Group_Seek_Transaction_SerialNumber", row.Group_Seek_Transaction_SerialNumber)
      window.location.href = './ConfirmContract.html'
    },

  },
})

